package com.archie.xunji.guangchang.adapters;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.archie.xunji.R;
import com.archie.xunji.guangchang.GuangchangListActivity;
import com.archie.xunji.guangchang.entity.GuangchangData;
import com.lidroid.xutils.BitmapUtils;

import java.util.List;

/**
 * Created
 * Author:bi[FR]
 * Date:15-11-10
 */
public class GuangchangAdapter extends RecyclerView.Adapter<GuangchangAdapter.MyViewHolder> {

    private List<GuangchangData> datas;
    private Context context;

    public  GuangchangAdapter(Context context, List<GuangchangData> datas) {
        this.datas = datas;
        this.context = context;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        MyViewHolder ret = null;
        View v = LayoutInflater.from(context).inflate(R.layout.item_recyclerview_guangchangfragment, parent, false);
        ret = new MyViewHolder(v);
        return ret;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        holder.tv_dizhi.setText(datas.get(position).getPlacename());
        holder.tv_username.setText(datas.get(position).getUsername());
        holder.tv_description.setText(datas.get(position).getDescription());
        holder.tv_biaoqian.setText(datas.get(position).getLabels());

        holder.iv_datu.setImageResource(R.mipmap.ic_launcher);
        holder.iv_touxiang.setImageResource(R.mipmap.ic_launcher);

        BitmapUtils bitmapUtils=new BitmapUtils(context);
        bitmapUtils.display(holder.iv_datu, datas.get(position).getImageurl());
        bitmapUtils.display(holder.iv_touxiang, "http://imagecdn.xunjimap.com/image/" + datas.get(position).getHeadurl());

    }


    @Override
    public int getItemCount() {
        int ret = 0;
        if (datas != null)
            ret = datas.size();
        return ret;
    }


     class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        ImageView iv_dizhi,iv_datu,iv_touxiang;
         TextView tv_dizhi,tv_username,tv_biaoqian,tv_description;


        public MyViewHolder(View itemView) {
            super(itemView);

            iv_datu= (ImageView) itemView.findViewById(R.id.iv_datu_item_recyclerview);
            iv_touxiang= (ImageView) itemView.findViewById(R.id.iv_touxiang_guangchangfragment);
            iv_dizhi= (ImageView) itemView.findViewById(R.id.iv_dizhi_recyclerview_guangchangfragment);
            tv_biaoqian= (TextView) itemView.findViewById(R.id.tv_biaoqian_item_recyclerview);
            tv_dizhi= (TextView) itemView.findViewById(R.id.tv_dizhi_recyclerview_guangchangragment);
            tv_username= (TextView) itemView.findViewById(R.id.tv_username_guangchangfragment);
            tv_description= (TextView) itemView.findViewById(R.id.tv_description_item_guangchangfragment);

            //后续处理点击事件的操作
            itemView.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            int position= getAdapterPosition();
            GuangchangData data=datas.get(position);
            Intent intent=new Intent(context,GuangchangListActivity.class);
            intent.putExtra("squareEntity",data);
            context.startActivity(intent);

        }
    }

}